package com.example.controller;

import com.example.common.Result;
import com.example.entity.Slideshow;
import com.example.service.SlideshowService;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/slideshow")
public class SlideshowController {

    @Resource
    private SlideshowService slideshowService;

    @PostMapping("/add")
    public Result add(@RequestBody Slideshow slideshow) {
        slideshowService.add(slideshow);
        return Result.success();
    }

    @PutMapping("/update")
    public Result update(@RequestBody Slideshow slideshow) {
        slideshowService.update(slideshow);
        return Result.success();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result delete(@PathVariable Integer id) {
        slideshowService.deleteById(id);
        return Result.success();
    }

    @GetMapping("/selectPage")
    public Result selectPage(@RequestParam(defaultValue = "1") Integer pageNum,
                             @RequestParam(defaultValue = "5") Integer pageSize,
                             Slideshow slideshow) {
        PageInfo<Slideshow> info = slideshowService.selectPage(pageNum, pageSize, slideshow);
        return Result.success(info);
    }
}
